﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PlayerInput : MonoBehaviour
{
    public string rightCode;
    public string leftCode;
    public string upCode;
    public string downCode;
    public string skillOneCode;
    public string skillTwoCode;
    public string skillThreeCode;

    public int mode;

    public float moveX = default;
    public float moveY = default;
    public Vector3 moveVec = default;
    public float mag = default;

    public bool isEnabled = true;    

    public bool shoot;
    public bool bomb;
    public bool laser;
    public bool buildBlock;
    public bool buildWater;
    public bool buildTree;




    // Start is called before the first frame update
    void Start()
    {
        
    }

    // Update is called once per frame
    void Update()
    {        
        
        moveX = (Input.GetKey(rightCode) ? 1.0f : 0.0f) - (Input.GetKey(leftCode) ? 1.0f : 0.0f);
        moveY = (Input.GetKey(upCode) ? 1.0f : 0.0f) - (Input.GetKey(downCode) ? 1.0f : 0.0f);                            
        
        if (!isEnabled) {
            moveX = 0;
            moveY = 0;
        }

        moveVec = SquareToCircle(moveX, moveY);
        mag = moveX * moveX + moveY * moveY;

        if (mode == 1)
        {
            shoot = false;
            bomb = false;
            laser = false;
            buildBlock = Input.GetKeyDown(skillOneCode);
            buildWater = Input.GetKeyDown(skillTwoCode);
            buildTree = Input.GetKey(skillThreeCode);

        }
        else if(mode == 2) {
            shoot = Input.GetKeyDown(skillOneCode);
            bomb = Input.GetKeyDown(skillTwoCode);
            laser = Input.GetKeyDown(skillThreeCode);
            buildBlock = false;
            buildWater = false;
            buildTree = false;
        }

    }

    Vector2 SquareToCircle(float x, float y)
    {
        Vector3 output = Vector3.zero;        
        output.x = x * Mathf.Sqrt(1 - (y * y) / 2);
        output.y = y * Mathf.Sqrt(1 - (x * x) / 2);
        return output;
    }
}
